package com.xxxx.yoyo.dao.impl;

import java.util.List;

import com.xxxx.yoyo.bean.Item;
import com.xxxx.yoyo.dao.IItemDao;
import com.xxxx.yoyo.util.DBUtils;

public class ItemDaoImpl implements IItemDao {

	/**
	 * 添加item
	 * @param item 购买项
	 * @return 返回添加的条数
	 */
	@Override
	public int insertItem(Item item) {
		String sql = "INSERT INTO item(price, amount, good_id, order_id) VALUES(?, ?, ?, ?)";
		int row = DBUtils.update(sql, item.getPrice(), item.getAmount(), item.getGoodId(), item.getOrderId());
		return row;
	}

	/**
	 * 根据订单id获取购买项列表
	 * @param orderId 订单id
	 * @return 返回购买项列表
	 */
	@Override
	public List<Item> selectItemListByOrderId(int orderId) {
		String sql = "SELECT * FROM item WHERE order_id = ?";
		List<Item> itemList = DBUtils.query(sql, Item.class, orderId);
		return itemList;
	}

}
